package com.qishui.mapcall.ui;

import com.qishui.mapcall.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.os.Bundle;
import android.widget.Toast;

public class Welcome extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);

		start(checkNetworkInfo());
	}

	private boolean checkNetworkInfo() {
		ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		State mobileState = conMan.getNetworkInfo(
				ConnectivityManager.TYPE_MOBILE).getState();
		State wifiState = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
				.getState();
		if (mobileState == State.CONNECTED || mobileState == State.CONNECTING) {
			return true;
		}
		if (wifiState == State.CONNECTED || wifiState == State.CONNECTING) {
			return true;
		} else {
			return false;
		}
	}

	private void start(boolean conState) {
		if (conState == true) {
			Intent intent = new Intent(this, Wizard.class);
			Toast.makeText(this, "check Network passed", Toast.LENGTH_LONG)
					.show();
			startActivity(intent);
			finish();
		} else {
			Toast.makeText(this, "no connection", Toast.LENGTH_LONG).show();
		}
	}

}